<HTML><HEAD><TITLE>yield(+ToC, -FromC)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">External Interface</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>yield(+ToC, -FromC)</H1>
Yield control to the C/C++ main program that has invoked ECLiPSe.
The arguments are used for passing data in and out.


<DL>
<DT><EM>ToC</EM></DT>
<DD>A term.
</DD>
<DT><EM>FromC</EM></DT>
<DD>A variable.
</DD>
</DL>
<H2>Description</H2>
   When ECLiPSe is used as an embedded component within an application
   written in C/C++, the ECLiPSe execution is conceptually a thread.
   Therefore, a yield-resume control flow model is used.
   On the C/C++ side, the ec_resume()/EC_resume() functions pass
   control to the ECLiPSe thread, while on the ECLiPSe side, the
   yield/2 predicate is used to pass control back.
   Data can be passed both ways: the ToC argument of yield/2 is passed
   to C/C++ via the second argument of ec_resume()/EC_resume() when it
   returns. Similarly a ec_resume()/EC_resume() first argument is
   passed to ECLiPSe as the FromC argument of yield/2.

<P>
   This mechanism is supposed to be used such that an ECLiPSe server
   loop is set up, and the host program resumes ECLiPSe repeatedly
   to have a request served.

<P>
   Note that, by default, ECLiPSe is set up as a server which calls
   posted goals. This is such a general mechanism that it is often
   not necessary to write a special-purpose server loop.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>yield(+, -) is det
</UL>
<H2>Examples</H2>
<PRE>
    % ECLiPSe server code
    start_server :-
        eclipse_server(dummy).

    eclipse_server(PrevResult) :-
        yield(PrevResult, Request),
        process_request(Request, NewResult),
        eclipse_server(NewResult).


    // C++ client code
    ec_init();
    post_goal("start_server");
    if (EC_resume() == EC_yield)
    {
        for(;;)
        {
	    // create a request
            ...
            if (EC_resume(request, result) != EC_yield);
                break;
            ...
            // use the result
        }
    }



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/externals/xget-3.html">xget / 3</A>, <A HREF="../../kernel/externals/xset-3.html">xset / 3</A>
</BODY></HTML>
